# Input.py: Alien Xenocide game story script
# Written by Victor Luna Freire - victorclf@live.com
# Copyright (c) Victor Luna Freire. All rights reserved.
# Sunday, July 15, 2009 17:48:50 PM
# Python 2.6.2
import pygame

class InputClass:

     def __init__(self):
          self.keys = []
          self.keys_to_release = []
     
     def remove_key(self, key):
          if key in self.keys:
               self.keys.pop(self.keys.index(key))
               return True
          return False
          
     
     def get_input(self):
          
          self.new_keys = []
          self.released_keys = []
          
          for i in self.keys_to_release:
               self.remove_key(i)
          
          self.keys_to_release = [] # keys to release processed, remove from the list
          
          for event in pygame.event.get():
               if event.type == pygame.QUIT:
                    return False
           
               if event.type == pygame.KEYDOWN:
                    self.new_keys.append(event.key)

               if event.type == pygame.KEYUP:
                    self.released_keys.append(event.key)

          for key in self.released_keys:
               if key in self.new_keys:
                    self.keys_to_release.append(key)
               else:
                    self.remove_key(key)
          
          
          self.keys.extend(self.new_keys)
          return True


     def check(self, key):
          return key in self.keys
     
     def check_once(self, key):
          return self.remove_key(key)


Input = InputClass()